package com.midian.service.advice.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.midian.common.dao.BaseDaoTemplet;
import com.midian.common.dao.OrderHelper;
import com.midian.common.dao.SearchHelper;
import com.midian.common.dao.SearchHelper.Type;
import com.midian.common.exception.BizException;
import com.midian.common.pager.Pager;
import com.midian.model.advice.Advice;
import com.midian.service.common.BaseService;
import com.midian.service.advice.IAdviceService;

/**
 * 建议表业务实现类
 * @author Mengfh
 *
 */
@Service("adviceService")
public class AdviceServiceImpl extends BaseService implements IAdviceService {
	/**建议表DAO*/
	private BaseDaoTemplet<Advice> adviceDAO;
	
	@Resource(name = "adviceDAO")
	public void setAdviceDAO(BaseDaoTemplet<Advice> adviceDAO) {
		this.adviceDAO = adviceDAO;
	}

	@Override
	public Advice add(Advice target) throws BizException {
		this.adviceDAO.add(target);
		return target;
	}

	@Override
	public void update(Advice target) throws BizException {
		this.adviceDAO.updateByConvertHql(target);
	}

	@Override
	public void delete(Serializable id) throws BizException {
		this.adviceDAO.delete(id);
	}

	@Override
	public void delete(Serializable[] ids) throws BizException {
		this.adviceDAO.delete(ids);
	}

	@Override
	public Advice get(Serializable id) throws BizException {
		return this.adviceDAO.get(id);
	}

	@Override
	public List<Advice> showList(Advice target, Pager pager, List<OrderHelper> helper) throws BizException {
		return this.adviceDAO.find(target, getSearchHelper(), helper, pager);
	}

	@Override
	public void opDelFlag(Serializable[] ids, Integer status) throws BizException {
		this.adviceDAO.opDelFlag(ids, status);
	}

	@Override
	protected List<SearchHelper> getSearchHelper() {
		String[] attrs = {"user","user.account","content","delFlag"};
		Type[] types = {Type.LEFTFETCH,Type.LIKE,Type.LIKE,Type.EQ};
		return SearchHelper.getSearchList(attrs, types);
	}
}
